/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package com.myapp.struts.servlets;

//~--- non-JDK imports --------------------------------------------------------

import com.myapp.struts.beans.ScheduleBean;
import com.myapp.struts.dao.Connect;

//~--- JDK imports ------------------------------------------------------------

import java.io.IOException;
import java.io.PrintWriter;

import java.util.*;

import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *   Document   : ScheduleMapper
 *   Created on : Apr 16, 2009, 8:29:01 AM
 *   Author     : K.Bala Lakshmi
 */
public class ScheduleMapper extends HttpServlet
 {
    private static final long serialVersionUID = 1L;

    // instantiating Driver class
    public Connect drv = new Connect();

    // instance variable declaration
    public ArrayList al, alt;
    boolean          bool;
    String           str;

    // method that contains business logic
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");

        PrintWriter    out = response.getWriter();
        ServletContext application;

        // get the values from jsp
        String        scheduleno   = request.getParameter("scheduleno");
        String        schedulename = request.getParameter("schedulename");
        String        schno        = request.getParameter("schno");
        java.sql.Date myDate       = new java.sql.Date(System.currentTimeMillis());
        String        date         = myDate.toString();
        int           scno         = Integer.parseInt(schno);

        System.out.println("date......" + date);

        try {
            ScheduleBean shb = new ScheduleBean();

            shb.setSchedule_No(scheduleno);
            shb.setSchedule_Name(schedulename);
            shb.setCreatedBy("admin");
            shb.setCreatedDt(date);
            shb.setSchedule_Status("1");

            if (scno == 1) {
                RequestDispatcher rd =
                    request.getRequestDispatcher("com/myapp/masters/schedule/schlevel1.jsp?scheduleno=" + scheduleno
                                                 + "&schedulename=" + schedulename + "&schlevel=" + scno);

                rd.forward(request, response);
            }

            if (scno == 2) {
                RequestDispatcher rd =
                    request.getRequestDispatcher("com/myapp/masters/schedule/schlevel1.jsp?scheduleno=" + scheduleno
                                                 + "&schedulename=" + schedulename + "&schlevel=" + scno);

                rd.forward(request, response);
            }            
        }                                        // end of try
                catch (Exception e) {
            System.out.println("CAUGHT AT ScheduleInsert SERVLET" + e);
        }                                        // end of catch
                finally {
            if (drv.mySql() != null) {
                try {
                    drv.mySql().close();
                    System.out.println("DATABASE CONNECTION TERMINATED");
                }                                // end of try
                        catch (Exception e) {    /* ignore close errors */
                }                                // catch block close
            }                                    // end of if
        }                                        // end of finally
    }                                            // End of service method
}    // End of class

